/**
 * 
 */
package com.common.bean;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.common.StarAppConst.IM_MESSAGE_KEY;
import com.common.allCommon.JSONObjecthelper;

/**
 * 用户被群主删除im消息
 * <br>Created 2014-11-7 下午4:57:39
 * @version  
 * @author   ChuXY		
 *
 * @see 	 
 */
public class GroupDeletedData extends AppMsgData implements ICommonImDataStruct,Parcelable,ICommonIMGroupInfo {

	/**
	 * 消息内容
	 */
	private String mMessage = "";

	/** 时间戳 */
	private long mTime = 0;

	/** 昵称 */
	private String mUniqueName = "";

	/** 用户id */
	private long mUid = 0;
	
	/**用户头像id*/
	private long mFileId=0;
	
	/** 消息类型 */
	private String mType = "";
	
	/**用户群id*/
	private long mGroupId=0;
	
	/**群图标id*/
	private long mGroupFileId=0;
	
	/**群名*/
	private String mGroupName="";
	/**
	 * Creates a new instance of GroupDeletedData.
	 * <br>Created 2014-11-7 下午5:15:31
	 * @param in
	 */
	
	public GroupDeletedData(Parcel in) {
		
	}

	/**
	 * @return the mType
	 */
	public String getType() {
		return mType;
	}

	/**
	 * @param mType the mType to set
	 */
	public void setType(String type) {
		this.mType = type;
	}

	/**
	 * @return the mMessage
	 */
	public String getMessage() {
		return mMessage;
	}

	/**
	 * @param mMessage the mMessage to set
	 */
	public void setMessage(String message) {
		this.mMessage = message;
	}

	/**
	 * @return the mTime
	 */
	public long getTime() {
		return mTime;
	}

	/**
	 * @param mTime the mTime to set
	 */
	public void setTime(long time) {
		this.mTime = time;
	}

	/**
	 * @return the mUniqueName
	 */
	public String getUniqueName() {
		return mUniqueName;
	}

	/**
	 * @param mUniqueName the mUniqueName to set
	 */
	public void setUniqueName(String uniqueName) {
		this.mUniqueName = uniqueName;
	}

	/**
	 * @return the mUid
	 */
	public long getUid() {
		return mUid;
	}

	/**
	 * @param mUid the mUid to set
	 */
	public void setUid(long uid) {
		this.mUid = uid;
	}

	/**
	 * @return the mFileId
	 */
	public long getFileId() {
		return mFileId;
	}

	/**
	 * @param mFileId the mFileId to set
	 */
	public void setFileId(long fileId) {
		this.mFileId = fileId;
	}


	@Override
	public String transDataToJSON() {
		JSONObject json=new JSONObject();
		try {
			json.put(IM_MESSAGE_KEY.TAG_TYPE, mType);
			json.put(IM_MESSAGE_KEY.TAG_MSG, mMessage);
			json.put(IM_MESSAGE_KEY.TAG_TIME, mTime);
			json.put(IM_MESSAGE_KEY.TAG_UNIQUENAME, mUniqueName);
			json.put(IM_MESSAGE_KEY.TAG_USERID, mUid);
			json.put(IM_MESSAGE_KEY.TAG_CHECK_CODE, mFileId);
			json.put(IM_MESSAGE_KEY.TAG_GROUP_ID, mGroupId);
			json.put(IM_MESSAGE_KEY.TAG_GROUP_NAME, mGroupName);
			json.put(IM_MESSAGE_KEY.TAG_GROUP_FID, mGroupFileId);
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		return json.toString();
	}

	@Override
	public void setDataFromJSON(String jsonString) {
		parseJson(jsonString);
	}

	@Override
	public void parseJson(String strJson) {
		if (TextUtils.isEmpty(strJson)) {
			return;
		}

		JSONObject jsonData = null;
		try {
			jsonData = new JSONObject(strJson);
		} catch (JSONException e) {
			return;
		}
		mType = JSONObjecthelper.getString(jsonData, IM_MESSAGE_KEY.TAG_TYPE);
		mMessage = JSONObjecthelper.getString(jsonData, IM_MESSAGE_KEY.TAG_MSG);
		mTime = JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_TIME);
		mUid = JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_USERID);
		mUniqueName = JSONObjecthelper.getString(jsonData,
				IM_MESSAGE_KEY.TAG_UNIQUENAME);
		mFileId = JSONObjecthelper.getLong(jsonData,
				IM_MESSAGE_KEY.TAG_CHECK_CODE);
		mGroupId = JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_GROUP_ID);
		mGroupFileId = JSONObjecthelper.getLong(jsonData,
				IM_MESSAGE_KEY.TAG_GROUP_FID);
		mGroupName= JSONObjecthelper.getString(jsonData, IM_MESSAGE_KEY.TAG_GROUP_NAME);
	}

	@Override
	public int describeContents() {
		return 0;
	}
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		super.writeToParcel(dest, flags);
		dest.writeString(mMessage);
		dest.writeLong(mTime);
		dest.writeString(mType);
		dest.writeString(mUniqueName);
		dest.writeLong(mUid);
		dest.writeLong(mFileId);
		dest.writeLong(mGroupId);
		dest.writeLong(mGroupFileId);
		dest.writeString(mGroupName);
	}


	@Override
	protected void parcelInData(Parcel in) {
		super.parcelInData(in);
		mMessage = in.readString();
		mTime = in.readLong();
		mType = in.readString();
		mUniqueName = in.readString();
		mUid = in.readLong();
		mFileId = in.readLong();
		mGroupId=in.readLong();
		mGroupFileId=in.readLong();
		mGroupName=in.readString();
	}
	
	public static final Parcelable.Creator<GroupDeletedData> CREATOR = new Creator<GroupDeletedData>() {

		@Override
		public GroupDeletedData[] newArray(int size) {
			return new GroupDeletedData[size];
		}

		@Override
		public GroupDeletedData createFromParcel(Parcel in) {
			return new GroupDeletedData(in);
		}
	};

	public GroupDeletedData() {
		super();
	}

	/**
	 * 
	 * <br>Created 2014-11-14 下午8:08:45
	 * @param groupId
	 * @author       ChuXY	
	*/
	
	@Override
	public void setGroupId(long groupId) {
		mGroupId=groupId;
	}

	/**
	 * 
	 * <br>Created 2014-11-14 下午8:08:45
	 * @return
	 * @author       ChuXY	
	*/
	
	@Override
	public long getGroupId() {
		return mGroupId;
	}

	/**
	 * 
	 * <br>Created 2014-11-14 下午8:08:45
	 * @param groupFileId
	 * @author       ChuXY	
	*/
	
	@Override
	public void setGroupFileId(long groupFileId) {
		mGroupFileId=groupFileId;
	}

	/**
	 * 
	 * <br>Created 2014-11-14 下午8:08:45
	 * @return
	 * @author       ChuXY	
	*/
	
	@Override
	public long getGroupFileId() {
		return mGroupFileId;
	}

	/**
	 * 
	 * <br>Created 2014-11-14 下午8:08:45
	 * @return
	 * @author       ChuXY	
	*/
	
	@Override
	public String getGroupName() {
		return mGroupName;
	}

	/**
	 * 
	 * <br>Created 2014-11-14 下午8:08:45
	 * @param groupName
	 * @author       ChuXY	
	*/
	
	@Override
	public void setGroupName(String groupName) {
		mGroupName=groupName;
	}

	/**
	 * 
	 * <br>Created 2014-11-14 下午10:21:18
	 * @return
	 * @author       ChuXY	
	*/
	
	@Override
	public long getLongExtraData() {
		return mGroupId;
	}

	@Override
	public String getStringExtraData() {
		return mGroupName;
	}
	
}
